/* eslint-disable react/prop-types */
import { Redirect, Route, useLocation } from 'react-router-dom'
import { hasToken } from '@/utils/storage'

export default function ProviteRoute ({ component: Com, path, ...res }) {
  const location = useLocation()
  return (
    <Route {...res} path={path} render={() => {
      if (hasToken()) return <Com></Com>
      return <Redirect to={{ pathname: '/login', state: { from: location.pathname } }
      }></Redirect>
    }}></Route >
  )
}
